package org.jeecg.access.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.access.constant.PlatformType;
import org.jeecg.access.entity.AccountData;
import org.jeecg.access.entity.PlatformTotal;
import org.jeecg.access.entity.WorkData;
import org.jeecg.access.platform.mapper.BiliCountMapper;
import org.jeecg.access.service.UnifiedPlatformService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @description: todo
 * @author: taogang
 * @date: 2025/7/28 8:28
 */
@Slf4j
@Service
public class BiliCountDataServiceImpl extends AbstractCountDataService implements UnifiedPlatformService {

    private final BiliCountMapper biliCountMapper;

    public BiliCountDataServiceImpl(BiliCountMapper biliCountMapper) {
        this.biliCountMapper = biliCountMapper;
    }

    @Override
    protected List<AccountData> queryAccountData() {
        return biliCountMapper.getDataList();
    }

    @Override
    protected List<WorkData> queryWorksData() {
        return biliCountMapper.getWorksList();
    }

    @Override
    public PlatformTotal getAccountTotal() {
        try {
            PlatformTotal platformTotal = biliCountMapper.getAccountNum();
            if (platformTotal == null) {
                platformTotal = new PlatformTotal();
            }
            platformTotal.setPlatformSign(PlatformType.BILIBILI.getCode());
            platformTotal.setReadCount(0);
            return platformTotal;
        } catch (Exception e) {
            log.error("获取B站账号统计数据失败", e);
            return new PlatformTotal();
        }
    }

    @Override
    public Object getPlatformTotal() {
        try {
            AccountData data = biliCountMapper.getPlatformTotal();
            return data != null ? data : new AccountData();
        } catch (Exception e) {
            log.error("获取B站平台总计数据失败", e);
            return new AccountData();
        }
    }

    @Override
    public String getPlatformTypeCode() {
        return PlatformType.BILIBILI.getCode();
    }
}

